package lhc.alg.top100;

/**
 * description:  https://leetcode.cn/problems/search-a-2d-matrix-ii/
 *
 *  搜索二位矩阵  二分 或者 z字形  蛇皮走位
 *
 * author: hongchen.liao
 * date:  2022/8/3
 */
public class _240_Search_a_2D_Matrix_II {

    //z
    class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            int m = matrix.length, n = matrix[0].length;
            int x = 0, y = n-1;
            while(x < m && y >= 0){
                if(matrix[x][y] == target){
                    return true;
                }else if(matrix[x][y] < target){
                    x++;
                }else{
                    y--;
                }
            }
            return false;
        }
    }

}
